package com.example.demo.controller;

import com.example.demo.service.StorageService;
import com.example.demo.web.AjaxResult;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class StorageController {

    private static final String SUCCESS = "SUCCESS";

    private static final String FAIL = "FAIL";

    @Autowired
    private StorageService storageService;

    @GetMapping(value = "/storage/{commodityCode}/{count}", produces = "application/json")
    public AjaxResult echo(@PathVariable String commodityCode, @PathVariable Integer count, @RequestHeader(value = "xxxx") String xxxx) {
        System.out.println(xxxx);
        log.info("Storage Service Begin ... xid: " + RootContext.getXID());
        int result = storageService.storage(count,commodityCode);
        log.info("Storage Service End ... ");
        if (result == 1) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

}
